package com.example.itrain.demo.controller;

import com.example.itrain.demo.model.Memo;
import com.example.itrain.demo.response.PageQuery;
import com.example.itrain.demo.response.Result;
import com.example.itrain.demo.service.MemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 备忘录 前端控制器
 * </p>
 *
 * @author rain
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/memo")
public class MemoController {
    @Autowired
    private MemoService memoService;

    @GetMapping("list")
    public Result list(PageQuery pageQuery) {
        List<Memo> list = memoService.list(pageQuery.Page());
        return Result.success(list);
    }

    @PostMapping("save")
    public Result save(@RequestBody Memo memo) {
        boolean save = memoService.save(memo);
        if (!save) {
            return Result.error("新增失败");
        } else {
            return Result.success("新增成功");
        }
    }
}
